// #define BOOST_TEST_MAIN
#include "stdafx.h"
#include "scanner.h"

BOOST_AUTO_TEST_SUITE(scanner);

BOOST_AUTO_TEST_CASE(store_value)
{
	Scanner a_scanner;
	a_scanner.setMemory(5);
	BOOST_REQUIRE_EQUAL(a_scanner.getMemory(), 5);
}

BOOST_AUTO_TEST_CASE(read_value_off_surface)
{
	Surface a_surface(15, 10);
	a_surface.setSquareValue(5, 7, 2);

	Scanner a_scanner;
	a_scanner.setSurface(&a_surface);

	a_scanner.setX(5);
	a_scanner.setY(7);

	BOOST_REQUIRE_EQUAL(a_scanner.getMemory(), a_surface.getSquareValue(5, 7));
}

BOOST_AUTO_TEST_CASE(move_right_middle)
{
	Surface a_surface(15, 10);
	a_surface.setSquareValue(6, 7, 3);

	Scanner a_scanner;
	a_scanner.setSurface(&a_surface);

	a_scanner.setX(5);
	a_scanner.setY(7);

	a_scanner.moveRight();

	BOOST_REQUIRE_EQUAL(a_scanner.getMemory(), a_surface.getSquareValue(6, 7));
}

BOOST_AUTO_TEST_CASE(move_right_edge)
{
	Surface a_surface(10, 15);
	a_surface.setSquareValue(0, 6, 3);

	Scanner a_scanner;
	a_scanner.setSurface(&a_surface);

	a_scanner.setX(9);
	a_scanner.setY(7);

	a_scanner.moveRight();

	BOOST_REQUIRE_EQUAL(a_scanner.getMemory(), a_surface.getSquareValue(0, 6));
}

BOOST_AUTO_TEST_CASE(move_left_middle)
{
	Surface a_surface(15, 10);
	a_surface.setSquareValue(4, 7, 3);

	Scanner a_scanner;
	a_scanner.setSurface(&a_surface);

	a_scanner.setX(5);
	a_scanner.setY(7);

	a_scanner.moveLeft();

	BOOST_REQUIRE_EQUAL(a_scanner.getMemory(), a_surface.getSquareValue(4, 7));
}

BOOST_AUTO_TEST_CASE(move_left_edge)
{
	Surface a_surface(10, 15);
	a_surface.setSquareValue(9, 8, 3);

	Scanner a_scanner;
	a_scanner.setSurface(&a_surface);

	a_scanner.setX(0);
	a_scanner.setY(7);

	a_scanner.moveLeft();

	BOOST_REQUIRE_EQUAL(a_scanner.getMemory(), a_surface.getSquareValue(9, 8));
}

BOOST_AUTO_TEST_CASE(move_up_middle)
{
	Surface a_surface(15, 10);
	a_surface.setSquareValue(4, 7, 3);

	Scanner a_scanner;
	a_scanner.setSurface(&a_surface);

	a_scanner.setX(4);
	a_scanner.setY(6);

	a_scanner.moveUp();

	BOOST_REQUIRE_EQUAL(a_scanner.getMemory(), a_surface.getSquareValue(4, 7));
}

BOOST_AUTO_TEST_CASE(move_up_edge)
{
	Surface a_surface(15, 10);
	a_surface.setSquareValue(4, 0, 3);

	Scanner a_scanner;
	a_scanner.setSurface(&a_surface);

	a_scanner.setX(4);
	a_scanner.setY(32767);

	a_scanner.moveUp();

	BOOST_REQUIRE_EQUAL(a_scanner.getMemory(), a_surface.getSquareValue(4, 0));
}

BOOST_AUTO_TEST_CASE(move_down_middle)
{
	Surface a_surface(15, 10);
	a_surface.setSquareValue(4, 7, 3);

	Scanner a_scanner;
	a_scanner.setSurface(&a_surface);

	a_scanner.setX(4);
	a_scanner.setY(8);

	a_scanner.moveDown();

	BOOST_REQUIRE_EQUAL(a_scanner.getMemory(), a_surface.getSquareValue(4, 7));
}

BOOST_AUTO_TEST_CASE(move_down_edge)
{
	Surface a_surface(15, 10);

	Scanner a_scanner;
	a_scanner.setSurface(&a_surface);

	a_scanner.setX(4);
	a_scanner.setY(0);

	a_scanner.moveDown();

	BOOST_REQUIRE_EQUAL(a_scanner.getX(), 4);
	BOOST_REQUIRE_EQUAL(a_scanner.getY(), 32767);
}

BOOST_AUTO_TEST_CASE(move_according_to_scanner)
{
	Surface a_surface(15, 10);

	Scanner a_scanner;
	a_scanner.setSurface(&a_surface);
	Scanner b_scanner;
	b_scanner.setSurface(&a_surface);

	a_scanner.setX(4);
	a_scanner.setY(5);

	b_scanner.setMemory(7);
	a_scanner.moveAccordingToScanner(b_scanner);
	BOOST_REQUIRE_EQUAL(a_scanner.getX(), 3);
	BOOST_REQUIRE_EQUAL(a_scanner.getY(), 5);

	b_scanner.setMemory(4);
	a_scanner.moveAccordingToScanner(b_scanner);
	BOOST_REQUIRE_EQUAL(a_scanner.getX(), 3);
	BOOST_REQUIRE_EQUAL(a_scanner.getY(), 6);

	b_scanner.setMemory(5);
	a_scanner.moveAccordingToScanner(b_scanner);
	BOOST_REQUIRE_EQUAL(a_scanner.getX(), 4);
	BOOST_REQUIRE_EQUAL(a_scanner.getY(), 6);

	b_scanner.setMemory(6);
	a_scanner.moveAccordingToScanner(b_scanner);
	BOOST_REQUIRE_EQUAL(a_scanner.getX(), 4);
	BOOST_REQUIRE_EQUAL(a_scanner.getY(), 5);
}

BOOST_AUTO_TEST_CASE(move_to_scanner_location)
{
	Surface a_surface(15, 10);
	Surface b_surface(25, 14);

	Scanner a_scanner;
	a_scanner.setSurface(&a_surface);
	Scanner b_scanner;
	b_scanner.setSurface(&b_surface);

	a_scanner.setX(4);
	a_scanner.setY(0);
	b_scanner.setX(21);
	b_scanner.setY(11);

	a_scanner.moveToScannerLocation(b_scanner);

	BOOST_REQUIRE_EQUAL(a_scanner.getX(), 21);
	BOOST_REQUIRE_EQUAL(a_scanner.getY(), 11);
	BOOST_REQUIRE_EQUAL(a_scanner.getSurface(), b_scanner.getSurface());
}

BOOST_AUTO_TEST_CASE(move_horizontally_vertically_to_n)
{
	Surface a_surface(15, 10);

	Scanner a_scanner;
	a_scanner.setSurface(&a_surface);

	a_scanner.setX(5);
	a_scanner.setY(2);

	a_scanner.moveHorizontally(9);
	a_scanner.moveVertically(7);

	BOOST_REQUIRE_EQUAL(a_scanner.getX(), 9);
	BOOST_REQUIRE_EQUAL(a_scanner.getY(), 7);
}

BOOST_AUTO_TEST_CASE(move_horizontally_vertically_to_scanner)
{
	Surface a_surface(15, 10);

	Scanner a_scanner;
	a_scanner.setSurface(&a_surface);

	Scanner b_scanner;
	b_scanner.setSurface(&a_surface);

	a_scanner.setX(5);
	a_scanner.setY(2);

	b_scanner.setX(9);
	b_scanner.setY(7);

	a_scanner.moveHorizontally(b_scanner);
	a_scanner.moveVertically(b_scanner);

	BOOST_REQUIRE_EQUAL(a_scanner.getX(), 9);
	BOOST_REQUIRE_EQUAL(a_scanner.getY(), 7);
}

BOOST_AUTO_TEST_CASE(write_number_from_scanner)
{
	Surface a_surface(15, 10);
	a_surface.setSquareValue(5, 7, 4);

	Scanner a_scanner;
	a_scanner.setSurface(&a_surface);

	Scanner b_scanner;
	b_scanner.setMemory(7);

	a_scanner.setX(5);
	a_scanner.setY(7);

	a_scanner.writeNumber(b_scanner);

	BOOST_REQUIRE_EQUAL(7, a_surface.getSquareValue(5, 7));
}

BOOST_AUTO_TEST_CASE(write_number_from_digit)
{
	Surface a_surface(15, 10);
	a_surface.setSquareValue(5, 7, 4);

	Scanner a_scanner;
	a_scanner.setSurface(&a_surface);

	a_scanner.setX(5);
	a_scanner.setY(7);

	a_scanner.writeNumber(7);

	BOOST_REQUIRE_EQUAL(7, a_surface.getSquareValue(5, 7));
}

BOOST_AUTO_TEST_CASE(write_complement)
{
	Surface a_surface(15, 10);
	a_surface.setSquareValue(5, 7, 4);

	Scanner a_scanner;
	a_scanner.setSurface(&a_surface);

	a_scanner.setX(5);
	a_scanner.setY(7);

	Scanner b_scanner;
	b_scanner.setMemory(5);

	a_scanner.writeComplement(b_scanner);

	BOOST_REQUIRE_EQUAL(2, a_surface.getSquareValue(5, 7));
}

BOOST_AUTO_TEST_CASE(exchange_number)
{
	Surface a_surface(15, 10);

	Scanner a_scanner;
	a_scanner.setSurface(&a_surface);
	Scanner b_scanner;
	b_scanner.setSurface(&a_surface);

	a_scanner.setX(5);
	a_scanner.setY(7);

	b_scanner.setX(11);
	b_scanner.setY(2);

	a_scanner.writeNumber(2);
	b_scanner.writeNumber(7);

	a_scanner.exchangeNumber(b_scanner);

	BOOST_REQUIRE_EQUAL(7, a_surface.getSquareValue(5, 7));
	BOOST_REQUIRE_EQUAL(2, a_surface.getSquareValue(11, 2));
}

BOOST_AUTO_TEST_CASE(or_number_from_scanner)
{
	Surface a_surface(15, 10);

	Scanner a_scanner;
	a_scanner.setSurface(&a_surface);

	a_scanner.setX(5);
	a_scanner.setY(7);

	Scanner b_scanner;
	b_scanner.setMemory(5);

	a_scanner.writeNumber(2);
	a_scanner.orNumber(b_scanner);

	BOOST_REQUIRE_EQUAL(7, a_surface.getSquareValue(5, 7));
}

BOOST_AUTO_TEST_CASE(or_number_from_digit)
{
	Surface a_surface(15, 10);

	Scanner a_scanner;
	a_scanner.setSurface(&a_surface);

	a_scanner.setX(5);
	a_scanner.setY(7);

	a_scanner.writeNumber(2);
	a_scanner.orNumber(5);

	BOOST_REQUIRE_EQUAL(7, a_surface.getSquareValue(5, 7));
}

BOOST_AUTO_TEST_CASE(and_number_from_scanner)
{
	Surface a_surface(15, 10);

	Scanner a_scanner;
	a_scanner.setSurface(&a_surface);

	a_scanner.setX(5);
	a_scanner.setY(7);

	Scanner b_scanner;
	b_scanner.setMemory(5);

	a_scanner.writeNumber(3);
	a_scanner.andNumber(b_scanner);

	BOOST_REQUIRE_EQUAL(1, a_surface.getSquareValue(5, 7));
}

BOOST_AUTO_TEST_CASE(and_number_from_digit)
{
	Surface a_surface(15, 10);

	Scanner a_scanner;
	a_scanner.setSurface(&a_surface);

	a_scanner.setX(5);
	a_scanner.setY(7);

	a_scanner.writeNumber(3);
	a_scanner.andNumber(5);

	BOOST_REQUIRE_EQUAL(1, a_surface.getSquareValue(5, 7));
}

BOOST_AUTO_TEST_CASE(add_number_from_scanner)
{
	Surface a_surface(15, 10);

	Scanner a_scanner;
	a_scanner.setSurface(&a_surface);

	a_scanner.setX(5);
	a_scanner.setY(7);

	Scanner b_scanner;
	b_scanner.setMemory(3);

	a_scanner.writeNumber(7);
	a_scanner.addNumber(b_scanner);

	BOOST_REQUIRE_EQUAL(2, a_surface.getSquareValue(5, 7));
}

BOOST_AUTO_TEST_CASE(add_number_from_digit)
{
	Surface a_surface(15, 10);

	Scanner a_scanner;
	a_scanner.setSurface(&a_surface);

	a_scanner.setX(5);
	a_scanner.setY(7);

	a_scanner.writeNumber(7);
	a_scanner.addNumber(3);

	BOOST_REQUIRE_EQUAL(2, a_surface.getSquareValue(5, 7));
}

BOOST_AUTO_TEST_CASE(subtract_number_from_scanner)
{
	Surface a_surface(15, 10);

	Scanner a_scanner;
	a_scanner.setSurface(&a_surface);

	a_scanner.setX(5);
	a_scanner.setY(7);

	Scanner b_scanner;
	b_scanner.setMemory(1);

	a_scanner.writeNumber(0);
	a_scanner.subtractNumber(b_scanner);

	BOOST_REQUIRE_EQUAL(7, a_surface.getSquareValue(5, 7));
}

BOOST_AUTO_TEST_CASE(subtract_number_from_digit)
{
	Surface a_surface(15, 10);
	a_surface.setSquareValue(5, 7, 4);

	Scanner a_scanner;
	a_scanner.setSurface(&a_surface);

	a_scanner.setX(5);
	a_scanner.setY(7);

	a_scanner.writeNumber(0);
	a_scanner.subtractNumber(1);

	BOOST_REQUIRE_EQUAL(7, a_surface.getSquareValue(5, 7));
}

BOOST_AUTO_TEST_CASE(multiply_number_by_scanner)
{
	Surface a_surface(15, 10);

	Scanner a_scanner;
	a_scanner.setSurface(&a_surface);

	a_scanner.setX(5);
	a_scanner.setY(7);

	Scanner b_scanner;
	b_scanner.setMemory(2);

	a_scanner.writeNumber(3);
	a_scanner.multiplyNumber(b_scanner);

	BOOST_REQUIRE_EQUAL(6, a_surface.getSquareValue(5, 7));
}

BOOST_AUTO_TEST_CASE(multiply_number_by_digit)
{
	Surface a_surface(15, 10);
	a_surface.setSquareValue(5, 7, 4);

	Scanner a_scanner;
	a_scanner.setSurface(&a_surface);

	a_scanner.setX(5);
	a_scanner.setY(7);

	a_scanner.writeNumber(3);
	a_scanner.multiplyNumber(2);

	BOOST_REQUIRE_EQUAL(6, a_surface.getSquareValue(5, 7));
}

BOOST_AUTO_TEST_CASE(divide_number_by_scanner)
{
	Surface a_surface(15, 10);

	Scanner a_scanner;
	a_scanner.setSurface(&a_surface);

	a_scanner.setX(5);
	a_scanner.setY(7);

	Scanner b_scanner;
	b_scanner.setMemory(2);

	a_scanner.writeNumber(4);
	a_scanner.divideNumber(b_scanner);

	BOOST_REQUIRE_EQUAL(2, a_surface.getSquareValue(5, 7));
}

BOOST_AUTO_TEST_CASE(divide_number_by_digit)
{
	Surface a_surface(15, 10);

	Scanner a_scanner;
	a_scanner.setSurface(&a_surface);

	a_scanner.setX(5);
	a_scanner.setY(7);

	a_scanner.writeNumber(4);
	a_scanner.divideNumber(2);

	BOOST_REQUIRE_EQUAL(2, a_surface.getSquareValue(5, 7));
}

BOOST_AUTO_TEST_CASE(set_memory_to_scanner)
{
	Scanner a_scanner;
	a_scanner.setMemory(1);

	Scanner b_scanner;
	b_scanner.setMemory(3);

	a_scanner.setMemory(b_scanner);

	BOOST_REQUIRE_EQUAL(a_scanner.getMemory(), 3);
}

BOOST_AUTO_TEST_CASE(set_memory_to_digit)
{
	Surface a_surface(15, 10);
	a_surface.setSquareValue(5, 7, 4);

	Scanner a_scanner;
	a_scanner.setSurface(&a_surface);

	a_scanner.setX(5);
	a_scanner.setY(7);

	a_scanner.setMemory(2);
	a_scanner.addNumber(3);

	BOOST_REQUIRE_EQUAL(5, a_surface.getSquareValue(5, 7));
}

BOOST_AUTO_TEST_SUITE_END();